class Solution(object):
    def triangleNumber(self, nums):
        t = 0
        nums.sort()
        n = len(nums)
        for i in range(n - 1, 1, -1):
            left = 0
            right = i - 1
            while left < right:
                if nums[left] + nums[right] > nums[i]:
                    t += right - left
                    right -= 1
                else:
                    left += 1
        return t



data = Solution()
nums = [2, 2, 3, 4]
print(data.triangleNumber(nums))
